package com.htgraph.util;

import org.w3c.dom.Document;

import java.io.IOException;
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;

import com.mxgraph.util.mxUtils;

/**
 * Created by IntelliJ IDEA.
 *
 * @author Dong Shufeng
 *         Date: 2011-2-14
 */
public class GraphLoader {
    public static Document parse(InputStream stream) {
        try {
            return mxUtils.parseXml(readStream(stream));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String readStream(InputStream stream) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
        StringBuffer result = new StringBuffer();
        String tmp = reader.readLine();

        while (tmp != null) {
            result.append(tmp + "\n");
            tmp = reader.readLine();
        }
        reader.close();
        return result.toString();
    }

}
